//一博主答案

#include <bits/stdc++.h>
using namespace std;

struct node {
  int N, C, M;
  vector<pair<int, int>>
      v; // 当前物理机数组，v.first为剩余cpu量，v.second为剩余内存
  map<int, pair<int, pair<int, int>>>
      mp; // 当前虚拟机映射，mp.first为所在物理机id，mp.second.first为所用cpu，mp.second.second为所用内存

  void init(int n, int c, int m) {
    N = n;
    C = c;
    M = m;
    for (int i = 0; i < n; i++)
      v.push_back({c, m});
  }

  pair<int, int> create(int vid, int vcpu, int vmem) {
    int id = -1, op = 0;
    int minn = 1000000009;
    for (int i = 0; i < v.size(); i++)
      if (v[i].first >= vcpu && v[i].second >= vmem) {
        int val = v[i].first * v[i].second -
                  (v[i].first - vcpu) * (v[i].second - vmem); // 关键代码
        if (val < minn) {
          minn = val;
          id = i;
        }
      }
    if (id != -1) { // 没找到合适的再新开
      id = N++;
      op = 1;
      v.push_back({C, M});
    }
    mp[vid] = {id, {vcpu, vmem}}; // 记录，使remove操作能o(1)解决
    v[id].first -= vcpu;
    v[id].second -= vmem;
    return {id, op};
  }

  void remove(int vid) {
    v[mp[vid].first].first += mp[vid].second.first;
    v[mp[vid].first].second += mp[vid].second.second;
  }
};
